from ping3 import ping
import IPy
import threading

ip = '192.168.1.0/24'

def my_ping(ip):
    result = ping(ip)
    if result:
        # return ip
        print(ip)
        
# 得到ip范围
try:
    ip_lst = IPy.IP(ip)
except Exception as e:
    print(e)
    exit()

t_lst = []
for ip in ip_lst:
    t = threading.Thread(target=my_ping, args=(str(ip), ))
    t_lst.append(t)
    t.start()
for t in t_lst:
    t.join()